package com.mythread2;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YJ
 * Date: 2023-10-06
 * Time: 18:28
 */
public class MyCallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建MyCallable对象（表示多线程要执行的任务）
        MyCallable mc = new MyCallable();
        //创建FutureTask对象，管理多线程运行的结果
        FutureTask<Integer> ft = new FutureTask<>(mc);
        //创建线程的对象
        Thread t = new Thread(ft);
        //启动线程
        t.setName("线程1");
        t.start();
        //获取多线程结果
        Integer result = ft.get();
        System.out.println(result);
    }
}
